package com.framework.modules.base.service.impl;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.Query;

import com.framework.modules.base.dao.UserDoingDao;
import com.framework.modules.base.entity.UserDoingEntity;
import com.framework.modules.base.service.UserDoingService;


@Service("userDoingService")
public class UserDoingServiceImpl extends ServiceImpl<UserDoingDao, UserDoingEntity> implements UserDoingService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<UserDoingEntity> page = this.selectPage(
                new Query<UserDoingEntity>(params).getPage(),
                new EntityWrapper<UserDoingEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Boolean isExist(UserDoingEntity entity) {
        List<UserDoingEntity> userDoingEntityList=this.baseMapper.listUserDoing(entity);
        return userDoingEntityList.size()==0?false:true;
    }

    @Override
    public Integer addDoing(UserDoingEntity entity) {
        return this.baseMapper.insert(entity);
    }

    @Override
    public Integer deleteDoing(UserDoingEntity entity) {
        return this.baseMapper.deleteDoing(entity);
    }

    @Override
    public Map<String, Boolean> getAttentUserAndLikeUser(Long uid, Long otherUid) {
        Map<String, Boolean> isFlag=new HashMap<>();
        isFlag.put("isAttent",false);
        isFlag.put("isLike",false);
        List<UserDoingEntity> entityList=baseMapper.selectList(new EntityWrapper<UserDoingEntity>()
                .eq("uid",uid).and().eq("object_uid",otherUid).and().eq("object_name","user"));
        for(UserDoingEntity entity:entityList){
            if("attent".equals(entity.getType())){
                isFlag.put("isAttent",true);
            }
            if("like".equals(entity.getType())){
                isFlag.put("isLike",true);
            }
        }
        return isFlag;
    }

    @Override
    public List<String> getMyLikeUserUid(Integer uid) {
        return this.baseMapper.getMyLikeUserUid(uid);
    }

    @Override
    public List<String> getMyAttentUserUid(Integer uid) {
        return this.baseMapper.getMyAttentUserUid(uid);
    }

    @Override
    public List<String> getLikeMeUserUid(Integer uid) {
        return this.baseMapper.getLikeMeUserUid(uid);
    }
}
